﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Presentation.Module.Scheduling.Interfaces.Views;
using Presentation.Module.Scheduling.Interfaces.ViewModels;
using Presentation.Module.Scheduling.ViewDto;


namespace Presentation.Module.Scheduling.Views
{
    /// <summary>
    /// Interaction logic for ScheduleStudyView.xaml
    /// </summary>
    public partial class ScheduleStudyView : UserControl, IScheduleStudyView
    {
        public ScheduleStudyView(IScheduleStudyViewModel viewModel)
        {
            InitializeComponent();

            // Set the viewmodel instance to the datacontext of this control so that the view model properties are 
            // available for databinding.
            this.DataContext = viewModel;
            viewModel.View = this;
        }

        /// <summary>
        /// Occurs when [view exit].
        /// </summary>
        public event Shell.Interfaces.ViewExit ViewExit;

        /// <summary>
        /// Cancels the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Cancel(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this.ViewExit != null)
            {
                this.ViewExit.Invoke();
            }
        }

        private void UpdateControls(object sender, RoutedEventArgs e)
        {
            BindingExpression bindExp = ((ItemsControl)e.OriginalSource).GetBindingExpression(ItemsControl.ItemsSourceProperty);

            bindExp.UpdateSource();
            bindExp.UpdateTarget();
            this.InvalidateVisual();
        }

    }
}
